<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/documentMyReady.js"></script>
    <style>
        .toggle{
            width: 200px;
            height: 200px;
            overflow: hidden;
            border: 1px solid #ccc;
            margin: 20px auto;
        }
        .toggle-control{
            text-align: center;
        }
    </style>
    <script>
        "use strict";
        document.myReady(function(){
            var toggleFold = document.getElementsByClassName('toggle-fold')[0];
            var toggleOpen = document.getElementsByClassName('toggle-open')[0];
            var toggle = document.getElementsByClassName('toggle')[0];
            var timeFold,timeOpen;
            var speed;
            var originHeight = toggle.offsetHeight;
            function init(){
                toggle.style.display = 'block';
                toggle.style.height = `${ toggle.offsetHeight }px`;
                speed = 10;
            }
            function funFold(){
                toggle.style.height = `${ parseInt(toggle.style.height) - speed }px`;
                if(parseInt(toggle.style.height) <= speed ){
                    clearInterval(timeFold);
                    toggle.style.display = 'none';
                }
            }
            function funOpen(){
                toggle.style.height = `${ parseInt(toggle.style.height) + speed }px`;
                if(parseInt(toggle.style.height) >= originHeight){
                    toggle.style.height = `${ originHeight }px`;
                    clearInterval(timeOpen);
                }
            }
            init();
            toggleFold.onclick = function(){
                timeFold = setInterval(funFold,1000/50);
            }
            toggleOpen.onclick = function(){
                toggle.style.display = 'block';
                timeOpen = setInterval(funOpen,1000/50);
            }
        });
    </script>
</head>
<body>
    <div class="toggle-control">
        <button class="toggle-fold">收起</button>
        <button class="toggle-open">展开</button>
    </div>
    <div class="toggle">
        <p>我是内容</p>
    </div>
</body>
</html>